package office.action.hr;

import java.util.List;
import office.action.hr.form.PurchaseEntryForm;
import office.service.hr.IPurchaseEntryService;
import platform.common.action.BaseAction;

public class PurchaseEntryAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private IPurchaseEntryService purchaseEntryService;
	private String id;
	private List<PurchaseEntryForm> dataList;
	private String proKey;
	private PurchaseEntryForm purchaseEntryForm;
	
	/**
	 * 跳转到采购编辑页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEditPurchaseEntry()throws Exception{
		if(null!=purchaseEntryForm.getId()){
			//根据id获取对象
			purchaseEntryForm = purchaseEntryService.getById(purchaseEntryForm.getId());
		}
		return "gotoEditPurchaseEntry";
	}
	/**
	 * 编辑采购信息
	 * @return
	 * @throws Exception
	 */
	public String editPurchaseEntry()throws Exception{
		try {
			String userId = getUserId();
			purchaseEntryForm.setEntryUserId(userId);
			String roleId = getUserRoleName();
			purchaseEntryForm.setEntryRole(roleId);
			purchaseEntryService.editPurchaseEntry(purchaseEntryForm);
			this.getAjaxMessagesJson().setMessage(true, "", "编辑成功!");
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	/**
	 * 获取采购信息集合
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public String getPurchaseEntryList()throws Exception{
		dataList = purchaseEntryService.getPurchaseEntryList();
		return "purchaseEntryList";
	}

	
	/**
	 * 初始化可用操作
	 * @return
	 * @throws Exception
	 */
	public String gotoEditXml()throws Exception{
		purchaseEntryForm = purchaseEntryService.getById(purchaseEntryForm.getId());
		return "editXml";
	}
	
	/**
	 * 初始化删除
	 * @return
	 * @throws Exception
	 */
	public String gotoDel()throws Exception{
		return "gotoDel";
	}
	/**
	 * 删除
	 * @return
	 * @throws Exception
	 */
	public String delData()throws Exception{
		try {
			purchaseEntryService.delData(purchaseEntryForm.getId());
			this.getAjaxMessagesJson().setMessage(true, "", "删除成功");
			
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	/**
	 * 确认提交审批页面
	 * @return
	 * @throws Exception
	 */
	public String gotoSubmitCheck()throws Exception{
		return "gotoSubmitCheck";
	}
	/**
	 * 提交审批
	 * @return
	 * @throws Exception
	 */
	public String submitCheck() throws Exception{
		try {
			purchaseEntryService.submitCheck(purchaseEntryForm.getId(), proKey);
			this.getAjaxMessagesJson().setMessage(true, "", "提交审批成功");
			
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}

	public IPurchaseEntryService getPurchaseEntryService() {
		return purchaseEntryService;
	}

	public void setPurchaseEntryService(IPurchaseEntryService purchaseEntryService) {
		this.purchaseEntryService = purchaseEntryService;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public List<PurchaseEntryForm> getDataList() {
		return dataList;
	}

	public void setDataList(List<PurchaseEntryForm> dataList) {
		this.dataList = dataList;
	}

	public String getProKey() {
		return proKey;
	}

	public void setProKey(String proKey) {
		this.proKey = proKey;
	}
	public PurchaseEntryForm getPurchaseEntryForm() {
		return purchaseEntryForm;
	}
	public void setPurchaseEntryForm(PurchaseEntryForm purchaseEntryForm) {
		this.purchaseEntryForm = purchaseEntryForm;
	}

}
